package com.company.behavioral.observer_pattern.concrete_subject;

import com.company.behavioral.observer_pattern.observer.Observer;
import com.company.behavioral.observer_pattern.subject.AllyControlCenter;

/**
 * 具体指挥
 * @ClassName ConcreteAllyControlCenter
 * @Author tiezheng.han
 * @Date 2020/9/7 10:51
 **/
public class ConcreteAllyControlCenter extends AllyControlCenter {
    public ConcreteAllyControlCenter(String allyName){
        System.out.println(allyName + "战队组建成功！");
        System.out.println("---------------------------");
        this.allyName = allyName;
    }

    /**
     * 实现通知方法
     * @param name
     */
    @Override
    public void notifyObserver(String name) {
        System.out.println(this.allyName + "战队紧急通知，盟友" + name + "遭受敌人攻击！");
        // 遍历观察者集合，调用每一个盟友（自己除外）的支援方法
        for (Object obg: players) {
            if (!((Observer) obg).getName().equalsIgnoreCase(name)){
                ((Observer) obg).help();
            }
        }
    }
}
